﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Dack_Web2.BUS;
namespace Dack_Web2
{
    public partial class DefaultStyle : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                String sql = "select * from LoaiSanPham";
                DTLoaiSanPham.DataSource = Sql_DataProvider.SQL_ExecuteTable(sql);
                DTLoaiSanPham.DataBind();
         
                if (CurrentContext.IsLogged)
                {
                    if (Session["TenDangNhap"] != null)
                    {
                        CurrentContext.User = Dack_Web2.User.FromId(CurrentContext.UserName);
                        CurrentContext.User.InitCart();
                        Response.Cookies["TenDangNhap"].Value = CurrentContext.User.TenDN;
                    }
                }
               
            }
            DisplayLoginPanel();
        }
        //    Response.Redirect("~/Login.aspx");
        private void DisplayLoginPanel()
        {
            btDangKy.Visible = !CurrentContext.IsLogged;
            btDangNhap.Visible = !CurrentContext.IsLogged;
            btDangXuat.Visible = CurrentContext.IsLogged;
            HyplUser.Visible = CurrentContext.IsLogged;
            HyplDonHang.Visible = CurrentContext.IsLogged;
            if (CurrentContext.IsLogged)
            {
                HyplUser.Text = CurrentContext.UserName;
                HyplUser.NavigateUrl = "~\\TaiKhoan.aspx";
                HyplDonHang.Text = "| Đơn hàng";
                HyplDonHang.NavigateUrl = "~/ThongTinGioHang.aspx";
                if (CongTyBUS.GetCongTy(CurrentContext.UserName) != null)
                {
                    HyplCongTy.Enabled = true;
                    HyplCongTy.Visible = true;
                    HyplCongTy.NavigateUrl = "~/CongTy.aspx";
                }
            }
        }

        protected void btDangXuat_Click(object sender, EventArgs e)
        {
            Session.Abandon();
            Response.Cookies["TenDangNhap"].Expires = DateTime.Now.AddDays(-1);
            Response.Redirect(Request.Url.ToString());
        }

        

        


    }
}